package edu.hubu.supermarketmanagementsystem.controller;

import com.sun.org.apache.xpath.internal.operations.Bool;
import edu.hubu.supermarketmanagementsystem.entity.Shelves;
import edu.hubu.supermarketmanagementsystem.service.ShelvesService;
import edu.hubu.supermarketmanagementsystem.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin  // 允许跨域请求
@RequestMapping("/shelf")  // 设置基本的 URL 路径
public class ShelvesController {

    // 注入 ShelvesService 服务
    @Autowired
    private ShelvesService shelvesService;
    // 添加货架
    @PostMapping("/add")
    public ResultVO<Boolean> addShelves(@RequestBody Shelves shelf) {
        return shelvesService.addShelf(shelf);
    }

    // 更新货架
    @PutMapping("/update")
    public ResultVO<Boolean> updateShelves(@RequestBody Shelves shelf) {
        return shelvesService.updateShelf(shelf);
    }

    // 删除货架
    @DeleteMapping("/delete/{shelfId}")
    public ResultVO<Boolean> deleteShelves(@PathVariable Integer shelfId) {
        return shelvesService.deleteShelf(shelfId);
    }

    // 根据货架 ID 查找货架
    @GetMapping("/find/{shelfId}")
    public ResultVO<Shelves> findShelves(@PathVariable Integer shelfId) {
        return shelvesService.getShelfById(shelfId);
    }

    // 获取所有货架
    @GetMapping("/all")
    public ResultVO<List<Shelves>> findAllShelves() {
        return shelvesService.getAllShelves();
    }

    // 根据区域 ID 查找货架
    @GetMapping("/findByArea/{areaId}")
    public List<Shelves> findShelvesByAreaId(@PathVariable int areaId) {
        return shelvesService.findShelvesByAreaId(areaId);
    }

    // 根据管理员 ID 查找货架
    @GetMapping("/findByAdmin/{adminId}")
    public List<Shelves> findShelvesByAdminId(@PathVariable int adminId) {
        return shelvesService.findShelvesByAdminId(adminId);
    }
}
